<%@ page language="java" contentType="text/html; charset=UTF-8"	 pageEncoding="UTF-8"%>
<%@ include file="../include/laypublic.jsp"%>
<!DOCTYPE html>
<html>
<head>
  <title>总包备案合同复制</title>
</head>
<style>
	.fieldset{
		margin-top: 5px;
		margin-bottom: 0px
	}
	.layui-legend{
		background-color:#5fb878;
		font-size:15px !important;
		width:140px;
	}
	.layui-form-item {
	    margin-bottom: 5px;
	    clear: both;
	    *zoom: 1;
	}
	.layui-form-label{width: 180px;}
</style>
<body>
	<div class="layui-fluid">
		<div class="layui-card">
			<div style="padding-top: 15px;">&nbsp;</div>
			<form class="layui-form" id="addInfo_form" lay-filter="addInfo_form">
				<div class="layui-tab layui-tab-brief" >
					<div class="layui-tab-content">
						<div class="layui-tab-item layui-show">
							
							<fieldset class="layui-elem-field layui-field-title fieldset" id="baseInfo" >
								<legend class="layui-btn layui-legend"
									style="text-align: left; cursor: default;" >项目基础信息 ></legend>
								<div class="layui-form-item">
									<div class="layui-inline">
										<label class="layui-form-label">申请公司</label>
										<div class="layui-input-inline">
											<input type="hidden" name="hrOrgid" value="${bindOrgId}">
											<input type="text" value="${bindOrgName}"
												style="border: 0px;" readonly="readonly" class="layui-input">
										</div>
									</div>
									<div class="layui-inline">
										<label class="layui-form-label">申请部门</label>
										<div class="layui-input-inline">
											<input type="hidden" name="hrDeptid" value="${bindDeptId}">
											<input type="text" value="${bindDeptName}"
												style="border: 0px;" readonly="readonly" class="layui-input">
										</div>
									</div>
									<div class="layui-inline">
										<label class="layui-form-label">申请人</label>
										<div class="layui-input-inline">
											<input type="hidden" name="hrStaffApplyid"
												value="${SESSION_KEY_USER_DETAIL.hrStaffId }"> <input
												type="text" name="staffname" value="${SESSION_KEY_USER_DETAIL.realName }"
												readonly="readonly" style="border: 0px" autocomplete="off"
												class="layui-input">
										</div>
									</div>
								</div>
								<div class="layui-form-item">
									<div class="layui-inline">
										<label class="layui-form-label">项目名称</label>
										<div class="layui-input-inline">
											<input type="hidden" id="id_proCode" name="proCode" value="">
											<input type="text" value="${cotBackupVo.proName}" 
												style="border:0px;width:220px" readonly="readonly" class="layui-input">
											<input type="hidden" name="proCodeAndCodes" value="${cotBackupVo.proCode}_${cotBackupVo.id}_${cotBackupVo.proName}" 
												style="border:0px;width:220px" readonly="readonly" class="layui-input">
										</div>
									</div>
									<div class="layui-inline">
										<label class="layui-form-label">区域公司</label>
										<div class="layui-input-inline">
											<input type="text" value="${cotBackupVo.orgAreaName}" id ="query-input-hrOrgAreName" style="border: 0px;width:220px" 
									 		 readonly="readonly" class="layui-input">
											<input type="hidden" name="hrOrgAreaId" value="${cotBackupVo.hrOrgAreaId}" id ="query-input-hrOrgAreName" style="border: 0px;width:220px" 
									 		 readonly="readonly" class="layui-input">
										</div>
									</div>
									<div class="layui-inline">
										<label class="layui-form-label">项目公司</label>
										<div class="layui-input-inline">
											<input type="text" name="hrOrgProName" value="${cotBackupVo.orgProName}" id ="query-input-hrOrgAreName" style="border: 0px;width:220px" 
									 		 readonly="readonly" class="layui-input">
											<input type="hidden" name="hrOrgProId" value="${cotBackupVo.hrOrgProId}" id ="query-input-hrOrgAreName" style="border: 0px;width:220px" 
									 		 readonly="readonly" class="layui-input">
										</div>
									</div>																	
								</div>
								<div class="layui-form-item">
									<div class="layui-inline">
										<label class="layui-form-label">实施机构</label>
										<div class="layui-input-inline">
											<input type="text" value="${cotBackupVo.carryOrg}" id="id_ImplementingBody" name="carryOrg" style="border: 0px;"
												readonly="readonly" class="layui-input">
										</div>
									</div>
									<div class="layui-inline">
										<label class="layui-form-label">项目负责人</label>
										<div class="layui-input-inline">
											<input type="text" value="${cotBackupVo.proLeader}" id="id_projectLeader" name="proLeader" style="border: 0px;"
												readonly="readonly" maxlength="10" lay-verify="required|COC"
												class="layui-input">
										</div>
									</div>
									<div class="layui-inline">
										<label class="layui-form-label">工程地址</label>
										<div class="layui-input-inline">
											<input type="hidden" id="sgCityId" name="sgCityId" value="${cotBackupVo.sgCityId}">
											<input type="text" value="${cotBackupVo.sgCityName}" id="id_projectAddress" name="projectAddress" value=""
												style="border: 0px;" readonly="readonly" class="layui-input">
										</div>
									</div>
								</div>
								<div class="layui-form-item">
									<div class="layui-inline">
										<label class="layui-form-label">合同名称</label>
										<div class="layui-input-inline">
											<input type="text" value="${cotBackupVo.cotName}" id="id_contractName" name="cotName"
												placeholder="请输入合同名称" maxlength="100" lay-verify="required|COC"
												autocomplete="off" class="layui-input">
										</div>
									</div>																	
									<div class="layui-inline">
										<label class="layui-form-label">总包单位</label>
										<div class="layui-input-inline">
											<select id="id_contractUnitName" name="sgCoopId"
												lay-filter="id_contractUnitName" lay-verify="required"
												lay-search>
												<option value="">请选择-总包单位</option>
												<c:if test="${not empty coopInfoList }">
													<c:forEach items="${coopInfoList}" var="coopInfo">
														<option value="${coopInfo.id }" <c:if test="${cotBackupVo.sgCoopId==coopInfo.id}">selected</c:if>>${coopInfo.coopName }
														</option>
													</c:forEach>
												</c:if>
											</select>										
										</div>
									</div>
									<div class="layui-inline" >
										<label class="layui-form-label" >签订日期</label>
										<div class="layui-input-inline">
											<input type="text" value="<fmt:formatDate value="${cotBackupVo.signDate }" pattern="yyyy-MM-dd"/>" class="layui-input" id="id_contractSigningDate" name="signDate" autocomplete="off" placeholder="合同签订日期" readonly />
										</div>
									</div>									
								</div>													
							</fieldset>						
							<fieldset class="layui-elem-field layui-field-title fieldset" id="contractPriceInfo" >
								<legend class="layui-btn layui-legend" style="text-align: left; cursor: default;" >合同信息 ></legend>
								<div class="layui-form-item">
									<div class="layui-inline">
										<label class="layui-form-label" >合同总价(元)(下浮前)</label>
										<div class="layui-input-inline">
											<input type="text" value="${cotBackupVo.sumTotalPre}" maxlength="13" lay-verify="required|floatNumber" id="Id_sumTotalPre" 
											name="sumTotalPre" placeholder="请输入下浮前合同总价" autocomplete="off" 
											onblur="calDownRate(this);arabiaToCN(this,1);" class="layui-input" >
										</div>
									</div>
									<div class="layui-inline">
										<label class="layui-form-label">合同总价(元)(下浮后)</label>
										<div class="layui-input-inline">
											<input type="text" value="${cotBackupVo.sumTotalAfter}" maxlength="13" lay-verify="required|floatNumber" id="Id_sumTotalAfter" 
											name="sumTotalAfter" placeholder="请输入下浮后合同总价" autocomplete="off" 
											onblur="calDownRate(this);arabiaToCN(this,1);" class="layui-input" >
										</div>
									</div>
									<div class="layui-inline">
										<label class="layui-form-label">整体下浮率(%)</label>
										<div class="layui-input-inline">
											<input type="text" value="${cotBackupVo.downRate}" lay-verify="required|floatNumber" id="Id_downRate" name="downRate" readonly="readonly"  class="layui-input" >
										</div>
									</div>
								</div>	
								<div class="layui-form-item" >
									<div class="layui-inline">
										<label class="layui-form-label">合同工期(天)</label>
										<div class="layui-input-inline">
											<input type="text" value="${cotBackupVo.periodDays }" id="id_contractPeriodDays" name="periodDays"
												maxlength="100" lay-verify="required|floatNumber" placeholder="请输入"
												onblur="checkValueverifyNumber2(this);" autocomplete="off" class="layui-input">
										</div>
									</div>
									<div class="layui-inline">
										<label class="layui-form-label">合同开工日期</label>
										<div class="layui-input-inline">
											<input type="text" class="layui-input" value="<fmt:formatDate value="${cotBackupVo.beginBuildDate }" pattern="yyyy-MM-dd"/>" autocomplete="off" readonly lay-verify="required"
												id="id_contractCommencementDate"
												name="beginBuildDate" 
												placeholder="合同开工日期">
										</div>
									</div>
									<div class="layui-inline">
										<label class="layui-form-label">合同竣工日期</label>
										<div class="layui-input-inline">
											<input type="text" value="<fmt:formatDate value="${cotBackupVo.endBuildDate }" pattern="yyyy-MM-dd"/>" id="id_contractCompletionDate" name="endBuildDate" readonly
												lay-verify="required" placeholder="合同竣工日期" autocomplete="off" class="layui-input">
										</div>
									</div>
								</div>
								<div class="layui-form-item">
									<div class="layui-inline">
										<label class="layui-form-label" >质量标准</label>
										<div class="layui-input-inline">
											<textarea id="id_soqMemo" placeholder="请输入质量标准" name="soqMemo"
											class="layui-textarea" lay-verify="required" maxlength="500"
											style="width: 899px; height: 90px;">${cotBackupVo.soqMemo }</textarea>
										</div>
									</div>
								</div>
								<div class="layui-form-item">
									<div class="layui-inline">
										<label class="layui-form-label" >预付款说明</label>
										<div class="layui-input-inline">
											<textarea id="id_preChargeMemo" placeholder="请输入预付款说明" name="preChargeMemo"
											class="layui-textarea" lay-verify="required" maxlength="500"
											style="width: 899px; height: 90px;">${cotBackupVo.preChargeMemo }</textarea>
										</div>
									</div>
								</div>
								<div class="layui-form-item">
									<div class="layui-inline">
										<label class="layui-form-label" >预付款比例(%) </label>
										<div class="layui-input-inline" >
											<input type="text" name="preChargeRate" value="${cotBackupVo.preChargeRate }" lay-verify="required|floatNumber" 
												onblur="isNumberAndFloat1(this);" placeholder="预付款比例" autocomplete="off" class="layui-input" />
										</div>
									</div>
									<div class="layui-inline">
										<label class="layui-form-label" >月度付款比例(%) </label>
										<div class="layui-input-inline" >
											<input type="text" name="monthChargeRate" value="${cotBackupVo.monthChargeRate }" lay-verify="required|floatNumber" 
												onblur="isNumberAndFloat1(this);" placeholder="月度付款比例" autocomplete="off" class="layui-input" />
										</div>
									</div>
									<div class="layui-inline">
										<label class="layui-form-label" >年度付款比例(%) </label>
										<div class="layui-input-inline" >
											<input type="text" name="yearChargeRate" value="${cotBackupVo.yearChargeRate }" lay-verify="required|floatNumber" 
												onblur="isNumberAndFloat1(this);" placeholder="年度付款比例" autocomplete="off" class="layui-input" />
										</div>
									</div>
								</div>
								<div class="layui-form-item">
									<div class="layui-inline">
										<label class="layui-form-label" >竣工付款比例(%) </label>
										<div class="layui-input-inline" >
											<input type="text" name="endChargeRate" value="${cotBackupVo.endChargeRate }" lay-verify="required|floatNumber" 
												onblur="isNumberAndFloat1(this);" placeholder="竣工付款比例" autocomplete="off" class="layui-input" />
										</div>
									</div>
									<div class="layui-inline">
										<label class="layui-form-label" >结算付款比例(%) </label>
										<div class="layui-input-inline" >
											<input type="text" name="settChargeRate" value="${cotBackupVo.settChargeRate }" lay-verify="required|floatNumber" 
												onblur="isNumberAndFloat1(this);" placeholder="结算付款比例" autocomplete="off" class="layui-input" />
										</div>
									</div>
									<div class="layui-inline">
										<label class="layui-form-label" >质保金比例(%) </label>
										<div class="layui-input-inline" >
											<input type="text" name="qaChargeRate" lay-verify="required|floatNumber" 
												onblur="isNumberAndFloat1(this);" value="${cotBackupVo.qaChargeRate}" placeholder="质保金比例" autocomplete="off" class="layui-input" />
										</div>
									</div>
								</div>																							
							</fieldset>						
														
							<fieldset class="layui-elem-field layui-field-title fieldset"
								id="baseInfo">
								<legend class="layui-btn layui-legend"
									style="text-align: left; cursor: default;">附件></legend>
								<div style="margin-top: 20px;">
									<div class="layui-form-item">
										<label class="layui-form-label" style="width: 350px;">支持pdf、excel、word、图片资料，可上传多个</label>
									</div>
									<div class="layui-form-item">
										<label class="layui-form-label">Word版合同文本</label>
										<div class="layui-input-block">
											<div class="layui-upload">
												<button type="button" class="layui-btn" id="1-upload-more">上传</button>
												<div class="layui-upload-list" id="1-upload-more-list">
												<c:forEach items="${cotBackupVo.cotBackupAtts }" var="fileAtt">
							              			<c:if test="${fileAtt.types == '1' }">
							              				<div class="layui-upload-img-div" id="upload_img_${fileAtt.id }">
							              					<c:choose>
								              					<c:when test="${fileAtt.fileSuffix == '.jpg' or fileAtt.fileSuffix == '.jpeg' or fileAtt.fileSuffix == '.png'}">
									              					<img src="${fileHttpPre }/${fileAtt.filePath }" title="${fileAtt.fileName}" class="layui-upload-img">
									              				</c:when>
									              				<c:otherwise>
									              					<img src="${ctx}/resources/images/${fn:substring(fileAtt.fileSuffix,1,5)}.jpg" title="${fileAtt.fileName}" class="layui-upload-img">
									              				</c:otherwise>
							              					</c:choose>
							              					<div class="mask">
							              						<a href="javascript:void(0)" onclick="showImg('${fileHttpPre}/${fileAtt.filePath }');">查看</a>
							              						<a href="javascript:void(0)" onclick="del('${fileAtt.id}')">删除</a>
							              						<input type="hidden" value="${fileAtt.types}|${fileAtt.fileName}${fileAtt.fileSuffix }||${fileAtt.filePath }" id="fileAtt_${fileAtt.id}" name="fileAtts1" ></input>
							              					</div>
							              					<p>${fileAtt.fileName}</p>
							              				</div>
							              			</c:if>
							              		</c:forEach>
												</div>
											</div>
										</div>
									</div>
									<div class="layui-form-item">
										<label class="layui-form-label">PDF版合同文本</label>
										<div class="layui-input-block">
											<div class="layui-upload">
												<button type="button" class="layui-btn" id="2-upload-more">上传</button>
												<div class="layui-upload-list" id="2-upload-more-list">
												<c:forEach items="${cotBackupVo.cotBackupAtts }" var="fileAtt">
							              			<c:if test="${fileAtt.types == '2' }">
							              				<div class="layui-upload-img-div" id="upload_img_${fileAtt.id }">
							              					<c:choose>
								              					<c:when test="${fileAtt.fileSuffix == '.jpg' or fileAtt.fileSuffix == '.jpeg' or fileAtt.fileSuffix == '.png'}">
									              					<img src="${fileHttpPre }/${fileAtt.filePath }" title="${fileAtt.fileName}" class="layui-upload-img">
									              				</c:when>
									              				<c:otherwise>
									              					<img src="${ctx}/resources/images/${fn:substring(fileAtt.fileSuffix,1,5)}.jpg" title="${fileAtt.fileName}" class="layui-upload-img">
									              				</c:otherwise>
							              					</c:choose>
							              					<div class="mask">
							              						<a href="javascript:void(0)" onclick="showImg('${fileHttpPre}/${fileAtt.filePath }');">查看</a>
							              						<a href="javascript:void(0)" onclick="del('${fileAtt.id}')">删除</a>
							              						<input type="hidden" value="${fileAtt.types}|${fileAtt.fileName}${fileAtt.fileSuffix }||${fileAtt.filePath }" id="fileAtt_${fileAtt.id}" name="fileAtts2" ></input>
							              					</div>
							              					<p>${fileAtt.fileName}</p>
							              				</div>
							              			</c:if>
							              		</c:forEach>
												</div>
											</div>
										</div>
									</div>
									<div class="layui-form-item">
										<label class="layui-form-label">盖章版合同文本</label>
										<div class="layui-input-block">
											<div class="layui-upload">
												<button type="button" class="layui-btn" id="3-upload-more">上传</button>
												<div class="layui-upload-list" id="3-upload-more-list">
												<c:forEach items="${cotBackupVo.cotBackupAtts }" var="fileAtt">
							              			<c:if test="${fileAtt.types == '3' }">
							              				<div class="layui-upload-img-div" id="upload_img_${fileAtt.id }">
							              					<c:choose>
								              					<c:when test="${fileAtt.fileSuffix == '.jpg' or fileAtt.fileSuffix == '.jpeg' or fileAtt.fileSuffix == '.png'}">
									              					<img src="${fileHttpPre }/${fileAtt.filePath }" title="${fileAtt.fileName}" class="layui-upload-img">
									              				</c:when>
									              				<c:otherwise>
									              					<img src="${ctx}/resources/images/${fn:substring(fileAtt.fileSuffix,1,5)}.jpg" title="${fileAtt.fileName}" class="layui-upload-img">
									              				</c:otherwise>
							              					</c:choose>
							              					<div class="mask">
							              						<a href="javascript:void(0)" onclick="showImg('${fileHttpPre}/${fileAtt.filePath }');">查看</a>
							              						<a href="javascript:void(0)" onclick="del('${fileAtt.id}')">删除</a>
							              						<input type="hidden" value="${fileAtt.types}|${fileAtt.fileName}${fileAtt.fileSuffix }||${fileAtt.filePath }" id="fileAtt_${fileAtt.id}" name="fileAtts3" ></input>
							              					</div>
							              					<p>${fileAtt.fileName}</p>
							              				</div>
							              			</c:if>
							              		</c:forEach>
												</div>
											</div>
										</div>
									</div>
									<div class="layui-form-item">
										<label class="layui-form-label">其他附件</label>
										<div class="layui-input-block">
											<div class="layui-upload">
												<button type="button" class="layui-btn" id="4-upload-more">上传</button>
												<div class="layui-upload-list" id="4-upload-more-list">
												<c:forEach items="${cotBackupVo.cotBackupAtts }" var="fileAtt">
							              			<c:if test="${fileAtt.types == '4' }">
							              				<div class="layui-upload-img-div" id="upload_img_${fileAtt.id }">
							              					<c:choose>
								              					<c:when test="${fileAtt.fileSuffix == '.jpg' or fileAtt.fileSuffix == '.jpeg' or fileAtt.fileSuffix == '.png'}">
									              					<img src="${fileHttpPre }/${fileAtt.filePath }" title="${fileAtt.fileName}" class="layui-upload-img">
									              				</c:when>
									              				<c:otherwise>
									              					<img src="${ctx}/resources/images/${fn:substring(fileAtt.fileSuffix,1,5)}.jpg" title="${fileAtt.fileName}" class="layui-upload-img">
									              				</c:otherwise>
							              					</c:choose>
							              					<div class="mask">
							              						<a href="javascript:void(0)" onclick="showImg('${fileHttpPre}/${fileAtt.filePath }');">查看</a>
							              						<a href="javascript:void(0)" onclick="del('${fileAtt.id}')">删除</a>
							              						<input type="hidden" value="${fileAtt.types}|${fileAtt.fileName}${fileAtt.fileSuffix }||${fileAtt.filePath }" id="fileAtt_${fileAtt.id}" name="fileAtts4" ></input>
							              					</div>
							              					<p>${fileAtt.fileName}</p>
							              				</div>
							              			</c:if>
							              		</c:forEach>
												</div>
											</div>
										</div>
									</div>
								</div>
							</fieldset>
						</div>
					</div>
				</div>

				<div class="layui-form-item"
					style="position: fixed ! important; right: 30px; bottom: 45%; z-index: 10000;">
					<div class="layui-input-block">
						<button
							class="layui-btn layui-bg-blue layui-btn-normal layui-btn-lg  layui-btn-radius"
							type="button" lay-submit lay-filter="addInfo_form_submit"
							id="addInfo_form_submit">
							<i class="layui-icon layui-icon-ok layuiadmin-button-btn"></i> 提交
						</button>
					</div>
				</div>
			</form>
		</div>
	</div>
</body>
</html>
<script type="text/javascript">
	var proName;
	var proNameid;
	//静态资源路径前缀
	var staticPath = '${fileHttpPre}';
	var stateJSON = <infopub:dicJson groupNo="A00010028" />;
	layui.config({
	    base: '${ctx}/resources/layuiadmin/' //静态资源所在路径
	  }).extend({
	    index: 'lib/index' //主入口模块
	  }).use(['index', 'set', 'upload', 'element', 'laydate'], function(){
	    var $ = layui.$
	    ,form = layui.form
	    ,element = layui.element
	    ,laydate = layui.laydate
	    ,upload = layui.upload;
		// 正则校验
		form.verify({
			//验证汉字
		    CHS:[
		    	/^[\u0391-\uFFE5]+$/
		    	,'只能输入汉字'
		  	],
		  	//名字校验
		  	COC: [
				/^[\u4e00-\u9fa5_a-zA-Z0-9]+$/
				,'请输入正确的名称'
		  	],
		  	//大于0的正整数
		  	intNumber:[
				/^[1-9]\d*$/
				,'请输入正确的数字'
		  	],
		  	//数字只能有两位小数
		  	floatNumber:[
				/^([-]?)([0-9](\d+)?(\.\d{1,2})?$)|(^\d\.\d{1,2}$)/
				,'请输入正确的数字'
		  	],
		  	telNumber:[/^[1][3,4,5,7,8,9][0-9]{9}$/
				  		,'请输入正确的号码'
			],
		  	//数字大于0，并只能有两位小数
		  	floatAmount:[
				/^([1-9](\d+)?(\.\d{1,2})?$)|(^\d\.\d{1,2}$)/
				//var pattern=/^((\d+\.\d*[1-9]\d{1})|(\d*[1-9]\d*\.\d{2}))$/; 
				,'请输入正确的数字'
		  	]
		});
		//附件格式控制				
		var fileFormatWord = 'application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document';
		var fileFormatPdf = 'application/pdf';
		var fileFormat = 'application/zip,application/x-rar-compressed,image/jpeg,image/png,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.ms-powerpoint,application/vnd.openxmlformats-officedocument.presentationml.presentation,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/pdf';
		uploadRender(1, upload,fileFormatWord, $);
		uploadRender(2, upload,fileFormatPdf, $);
		uploadRender(3, upload,fileFormat, $);
		uploadRender(4, upload,fileFormat, $);
		
		laydate.render({
	     	elem: '#id_contractSigningDate'
	     	,trigger: 'click'
 		});
		//通过合同开工日期和合同工期天计算合同竣工日期
		laydate.render({
			elem : '#id_contractCommencementDate',
			trigger : 'click',
			done : function(value, date) {
				var contractconPeriodDaysValue = $(
						"#id_contractPeriodDays").attr("value");//合同工期（天）
				var rgx1 = /^[1-9]\d*$/;
				if (rgx1.test(contractconPeriodDaysValue)) {//请输入正确数字，且必须为正整数！
					var contractCompletionDate = addDate(value,contractconPeriodDaysValue);
					$("#id_contractCompletionDate").val(contractCompletionDate);//合同竣工日期
				}
				form.render();
			}
		});
		
		laydate.render({//合同竣工日期
			elem : '#id_contractCompletionDate',
			trigger : 'click'
		});	
		
		form.on('select(add_select_proId)', function(data) {
			var id = data.value;
			proNameid = data.value;
			proName = data.elem.getAttribute('proName');
	
			if(id==''||id==null){
	    		layer.msg('请选择项目名称',{icon: 1});
	    		return;
	    	}else{
	    		getCotBackupByProCode(id); 
	    	}	
		});
		
		form.on('submit(addInfo_form_submit)', function(data) {
			//Word版合同文本
			if ($("input[name=fileAtts1]").length < 1) {
				layer.msg("Word版合同文本未上传", {
					icon : 0
				});
				return;
			}
			//PDF版合同文本
			if ($("input[name=fileAtts2]").length < 1) {
				layer.msg("PDF版合同文本未上传", {
					icon : 0
				});
				return;
			}
			$("#addInfo_form_submit").removeAttr("lay-submit").removeClass("layui-bg-blue").addClass("layui-btn-disabled");
			//提交 Ajax 成功后，静态更新表格中的数据	
               $.ajax({
                   type : 'post',
         		   url : basePath + '/cotBackup/save',
                   data: $('#addInfo_form').serialize(),
         		   success:function(result){
         				if(result.success){
         					layer.closeAll('loading'); //关闭loading
         					layer.msg('提交单据成功~',{icon: 1});
         					//两秒后关闭当前页面
         					setTimeout(function(){
         						/**
         						 * 查找父菜单，并刷新
         						 */
         						var topDoc = $(window.top.document);
         						var path = basePath + '/cotBackup/list';
         						// 获取页面名称
         						var name = topDoc.find(".layui-nav-item [lay-href^='" + path + "']").text();
         						if(name == '' || name == null){
         							name = '总包备案合同';
         						}
         						window.parent.layui.index.openTabsPage(path, name);
         						var iframe = window.parent.layui.admin.tabsBody(window.parent.layui.admin.tabsPage.index).find(".layadmin-iframe");
         						iframe[0].contentWindow.location.reload(true);
         						
         						/**
         						 * 关闭当前页
         						 */
         						var currPath = basePath + '/cotBackup/toCopy';
         						var layid = topDoc.find("li[lay-id^='" + currPath + "']").attr('lay-id');
         						window.parent.layui.element.tabDelete('layadmin-layout-tabs', layid);//关闭当前页
         				        }, 2000);
         				}else{
         					layer.closeAll('loading'); //关闭loading
           					$("#addInfo_form_submit").removeClass("layui-btn-disabled").addClass("layui-bg-blue").attr("lay-submit","");
         					layer.msg(result.msg,{icon: 7});
         			  	}
         			}
              });
		});
	});

	var uploadRender = function(id, upload, fileFormat,$) {
		upload.render({
			elem : '#' + id + '-upload-more',
			url : basePath + '/cotBackup/uploadAtt/',
			data : {
				types : id
			},
			multiple : true,
			accept : 'file',
			acceptMime : fileFormat,
			before : function(obj) {
				layer.load();
			},
			done : function(res) {
				if (res.code > 0) {
					layer.closeAll('loading');
					return layer.msg(res.msg, {
						icon : 7
					});
				}
				if (res.entity != null && res.entity.length > 0) {
					for ( var i in res.entity) {
						var cotBackup = res.entity[i];
						var arr = cotBackup.split("|");
						var imgSrc = "";
						var suffix = arr[1].substring(arr[1]
								.lastIndexOf(".") + 1, arr[1].length);
						if (suffix == 'jpg' || suffix == 'png') {
							imgSrc = "${fileHttpPre}/" + arr[3];
						} else {
							imgSrc = "${ctx}/resources/images/"
									+ suffix + ".jpg";
						}
						$('#' + id + '-upload-more-list')
								.append(
										'<div class="layui-upload-img-div" id="upload_img_'+arr[2]+'"><img src="'+imgSrc+'" title="'+ arr[1] +'" class="layui-upload-img"><div class="mask"><a href="javascript:void(0)" onclick="showImg(\''
												+ "${fileHttpPre}"
												+ arr[3]
												+ '\');">查看</a><a href="javascript:void(0)" onclick="del(\''
												+ arr[2]
												+ '\')";>删除</a></div><p>'
												+ arr[1]
												+ '</p><input type="hidden" value="'+cotBackup+'" id="fileAtt_'+arr[2]+'" name="fileAtts'+id+'" ></input></div>');
					}
				}
			},
			allDone : function(obj) {
				layer.closeAll('loading');
			},
			error : function() {
				layer.closeAll('loading');
				layer.msg("上传失败，请稍后再试~", {
					icon : 7
				});
			}
		});
	}
	//删除文件
	function del(index) {
		layui.$("#fileAtt_" + index).remove();
		layui.$("#upload_img_" + index).remove();
	}

	//根据url查看文件
	function showImg(url) {
		var openWin = window.open(url,'','left=410,height=768, width=1024, top=200,  toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no');
	}
	
	//根据项目名称带出需要的总包备案合同字段
	function getCotBackupByProCode(id) {		
		var $ = layui.$, form = layui.form
		var proCodeAndCodes = id;
		$.ajax({
			type : "POST", //提交方式  
			url : "${ctx}/cotBackup/getCotBackupByProCode",//路径  
			data : {
				"proCodeAndCodes" : proCodeAndCodes
			},	//数据，这里使用的是Json格式进行传输  
			success : function(result) {	//返回数据根据结果进行相应的处理 
				if (result.flag == true) {
					if(result.cotBackupProCode!=null){
						$("#id_proCode")
								.attr("value", result.cotBackupProCode.proCode);//项目编号
						if (result.cotBackupProCode.orgAreName != null) {
							$("#id_regionalCompany").attr("value",
									result.cotBackupProCode.orgAreName);//区域公司
							$("#areaId").attr("value",
									result.cotBackupProCode.hrOrgAreaId);//区域公司id
						} else {
							$("#id_regionalCompany").attr("value", "暂时为空不可编辑");//区域公司
						}
						if (result.cotBackupProCode.hrOrgProId != null) {
							$("#hrOrgProId").attr("value",
									result.cotBackupProCode.hrOrgProId);//项目公司id	
							$("#id_projectCompany").attr("value",
									result.cotBackupProCode.orgProName);//项目公司	
						} else {
							$("#id_projectCompany").attr("value", "暂时为空不可编辑");//项目公司
						}
						$("#id_projectAddress").attr("value",
								result.cotBackupProCode.sgCityName);//工程地址
						$("#sgCityId").attr("value",
								result.cotBackupProCode.sgCityId);//工程地址城市id		
						$("#id_ImplementingBody").attr("value",
								result.cotBackupProCode.carryOrg);//实施机构
						$("#id_projectLeader").attr("value",
								result.cotBackupProCode.proLeader);//项目负责人
						
					}else{
						$("#id_proCode").attr("value", '');//项目编号
						$("#areaId").attr("value",'');//区域公司id
						$("#id_regionalCompany").attr("value", '');//区域公司
						$("#id_projectCompany").attr("value", '');//项目公司
						$("#hrOrgProId").attr("value",'');//项目公司id
						$("#id_projectAddress").attr("value",'');//工程地址
						$("#sgCityId").attr("value",'');//工程地址城市id		
						$("#id_ImplementingBody").attr("value",'');//实施机构
						$("#id_projectLeader").attr("value",'');//项目负责人				
					}					
					form.render();
				}
			}
		});
	}
	var rgx = /^([-]?)([0-9](\d+)?(\.\d{1,2})?$)|(^\d\.\d{1,2}$)/;
	
	/**
	 * [dateAddDays 从某个日期增加n天后的日期]
	 * @param  {[string]} dateTemp  [日期字符串]
	 * @param  {[int]} days [增加的天数]
	 * @return {[string]}[增加n天后的日期字符串]
	 */
	 function addDate(dateTemp, days) {
	    var nDate = new Date(dateTemp);
	    var millSeconds = Math.abs(nDate) + (days * 24 * 60 * 60 * 1000);
	    var rDate = new Date(millSeconds);
	    var year = rDate.getFullYear();
	    var month = rDate.getMonth() + 1;
	    month = month < 10 ? "0"+month : month;
	    var date = rDate.getDate();
	    date = date < 10 ? "0"+date : date;
	    return (year + "-" + month + "-" + date);
	}
	// 校验合同工期(天)输入框
	function checkValueverifyNumber2(obj) {
		var $ = layui.$, form = layui.form
		if (obj.value == '' || obj.value == null) {
			return;
		}
		var rgxInt = /^[1-9]\d*$/;//校验正整数
		var boolrgx = rgxInt.test(obj.value);// true 
		if (boolrgx) {
			if (obj.id == "id_contractPeriodDays") {//合同工期(天)的id
				$("#id_contractPeriodDays").attr("value",obj.value);//合同工期(天)赋值
			}
			var startDate = $("#id_contractCommencementDate").val();
			if(startDate!=null&&startDate!=''){
				var contractCompletionDate = addDate(startDate,obj.value);
				$("#id_contractCompletionDate").val(contractCompletionDate);//合同竣工日期
			}else{
				$("#id_contractCompletionDate").val('');
			}
			form.render();
		} else {
			obj.value=0;
			var startDate = $("#id_contractCommencementDate").val();
			if(startDate!=null&&startDate!=''){
				$("#id_contractCompletionDate").val(startDate);//合同竣工日期
			}else{
				$("#id_contractCompletionDate").val('');
			}
			layer.msg('请输入正确数字，且必须为正整数！');
			form.render();
		}
	}
	// 校验需要输入数字的input框(请输入正确数字，且保留两位小数！)
	function isNumberAndFloat1(str) {
		var $ = layui.$
		if (str.value == '' || str.value == null) {
			return;
		}		
		var boolrgx = rgx.test(str.value);// true 
		if (boolrgx) {
			return true;
		} else {
			str.value =0;
			layer.msg('请输入正确数字，且保留两位小数！');
		}
	}
	//通过下浮前合同总价和下浮后合同总价计算整体下浮率
	function calDownRate(obj){
		var $ = layui.$
		if (obj.value == '' || obj.value == null) {
			return;
		}
		var boolrgx = rgx.test(obj.value);// true 
		if (boolrgx) {
			var sumTotalPre = 0;//下浮前合同总价
			var sumTotalAfter = 0;//下浮后合同总价
			var downRate = 0;//整体下浮率
			if (obj.id == "Id_sumTotalPre"){
				sumTotalPre = parseFloat(obj.value);
				if($("#Id_sumTotalAfter").val()==null||$("#Id_sumTotalAfter").val()==''){
					sumTotalAfter = 0;
				}else{
					sumTotalAfter = parseFloat($("#Id_sumTotalAfter").val());
				}				
				if(sumTotalPre!=0&&sumTotalAfter!=0){
					downRate = (1 - parseFloat(sumTotalAfter/sumTotalPre))*100;
				}else{
					downRate = 0;
				}
				$("#Id_downRate").val(downRate.toFixed(2));
			}else if(obj.id == "Id_sumTotalAfter"){
				sumTotalPre = parseFloat($("#Id_sumTotalPre").val());
				if($("#Id_sumTotalPre").val()==null||$("#Id_sumTotalPre").val()==''){
					sumTotalPre = 0;
				}else{
					sumTotalAfter = parseFloat(obj.value);
				}				
				if(sumTotalPre!=0&&sumTotalAfter!=0){
					downRate = (1 - parseFloat(sumTotalAfter/sumTotalPre))*100;
				}else{
					downRate = 0;
				}
				$("#Id_downRate").val(downRate.toFixed(2));
			}			
			return true;
		} else {
			obj.value =0;
			$("#Id_downRate").val(0);
			layer.msg('请输入正确数字，且保留两位小数！');
		}
		
	}
</script>